package com.sxhuayuan.parking.dao;

import com.sxhuayuan.parking.entity.OrderRefund;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface OrderRefundDao extends BaseDao<OrderRefund, Long> {

    @Query(value = "select sum(if(ho.platform = 0, r.refund_money, 0)) wx_refund," +
            "       sum(if(ho.platform = 1, r.refund_money, 0)) ali_refund " +
            "from hypk_order_refund r" +
            "         left join hypk_order ho on r.order_id = ho.id" +
            "         left join hypk_agent ha on ho.agent_id = ha.id" +
            "         left join hypk_agent_relation har on ha.id = har.child_id " +
            "where r.is_success = 1" +
            "  and har.parent_id = ?1" +
            "  and r.create_date >= ?2" +
            "  and r.create_date < ?3",nativeQuery = true)
    List<Object> sumByAgentAndCreateDate(Long agentId, String startTime, String endTime);
}
